﻿i
function GetCheckCtlId(pageRuleHiddenId) {
	var ss = pageRuleHiddenId.toString();
	var str = "_page_rule";
	var val = "";
	var endIndex = (ss.indexOf(str));
	if(endIndex>-1)
		val = ss.substr(0, endIndex);
	return val;
}

function GetPageRuleProValue(proInfo, proName) {
	var strProName = "";
	var startIndex = -1
	var endIndex = 0;
	do {
		endIndex = proInfo.toString().indexOf(":", startIndex);
		if (endIndex >= 0)
		{
			strProName = proInfo.toString().substring(0, endIndex);
			startIndex = endIndex + 1;
		}
		else
			break;
	} while (strProName != "" && strProName!=proName)
	var val = "";
	if (startIndex > -1) {
		var valStartIndex = startIndex;
		var valEndIndex = proInfo.toString().indexOf(",", startIndex);
		if (valEndIndex > -1)
			val = (proInfo.toString().substring(valStartIndex, valEndIndex));
		else
			val = (proInfo.toString().substr(valStartIndex, proInfo.toString().length - valStartIndex));
	}
	return val;
}

var errMsgId = "page_checkMsg";

function SubCheck(checkCtlId, typeName) {
	var ctl = $("#" + checkCtlId);
		if (typeName == "必填") {
			var txtValue = ctl.val();
			var bgColor = "#FFFFFF"
			var errMsg = $("#" + errMsgId);
			if (txtValue == "") {
				bgColor = ("yellow");
				ctl.select();
				var checkObjProaName = (ctl.parent().prev().text());
				var errStr = checkObjProaName + typeName;
				errMsg.val(errMsg.val() + errStr + "\r\n");
				ctl.attr("title", errStr);
			}
			ctl.css("background-color", bgColor.toString());
		}
}

function SetCtlCheck() {
	var errMsg = $("#" + errMsgId);
	errMsg.val("");
	$(document).find("input[class='page_rule']").each(function(i) {
		var id = $(this).attr("id");
		var proInfo = $(this).val();
		var typeName = GetPageRuleProValue(proInfo, "TypeName");
		var checkCtlId = GetCheckCtlId(id);
		var checkCtl = $("#" + checkCtlId);
		if (checkCtlId.length > 0) {
			SubCheck(checkCtlId, typeName);
		}
	});
}

$(document).ready(function() {
	$("body").append("<input id='" + errMsgId + "' type='hidden' value='' />");
	$("#btnEnter").mousedown(function() {
		SetCtlCheck();
		var errMsg = $("#" + errMsgId);
		if (errMsg.val() != "") {
			//alert(errMsg.val());
			return false;
		}
	});
});
